#include"process.h"
#include<unistd.h>
#include<string.h>
#include<stdio.h>

#define TYPE '#'
#define LENGTH 100//倒计时
void Process() 
{
    const char *symb="|/-\\";
    char bar[LENGTH];
    memset(bar, '\0', sizeof(bar));
    int i = 0;
    while (i <= LENGTH) 
    {
        printf("[%-100s][%d%%][%c]\r", bar, i * 100 / LENGTH,symb[i%4]);
        bar[i] = TYPE;
        fflush(stdout);
        usleep(20000);
        i++;
    }
    printf("\n");
}


void FlushProcess(double target, double current)
{
  const char *symb="|/-\\";
  static int index = 0;
  double rate=(current/target)*100;
  int cnt=(int)rate;

  char bar[LENGTH];
  memset(bar,'\0',sizeof(bar));
  int i;
  for(i=0;i<=cnt;i++)
    bar[i]=TYPE;
  const char* loveMessage = "我爱陈彦静 ";
  printf("[%-100s][%.2lf%%][%c] %s\r",bar,rate,symb[index++],loveMessage);
  index%=4;
  fflush(stdout);
  if(rate>=100.0)
    printf("\n我对陈彦静的爱已拉满！\n");
}

